package com.example.demo.pojos;

import javax.persistence.*;
import java.math.BigDecimal;
import java.sql.Timestamp;
import java.util.List;
import java.util.Objects;

@Entity
public class Product {
    private int productId;
    private String productName;
    private String productModel;
    private BigDecimal price;
    private int number;
    private int status;
    private Timestamp time;
    private Order htdd;
    private Pddetails cpxq;
    private Pdtype cpfl;
    private int pictureId;
    private List<Picture> tp;

    @Id
    @Column(name = "product_id", nullable = false)
    public int getProductId() {
        return productId;
    }

    public void setProductId(int productId) {
        this.productId = productId;
    }

    @Basic
    @Column(name = "product_name", nullable = false, length = 255)
    public String getProductName() {
        return productName;
    }

    public void setProductName(String productName) {
        this.productName = productName;
    }

    @Basic
    @Column(name = "product_model", nullable = true, length = 255)
    public String getProductModel() {
        return productModel;
    }

    public void setProductModel(String productModel) {
        this.productModel = productModel;
    }

    @Basic
    @Column(name = "price", nullable = false, precision = 2)
    public BigDecimal getPrice() {
        return price;
    }

    public void setPrice(BigDecimal price) {
        this.price = price;
    }

    @Basic
    @Column(name = "number", nullable = false)
    public int getNumber() {
        return number;
    }

    public void setNumber(int number) {
        this.number = number;
    }

    @Basic
    @Column(name = "status", nullable = false)
    public int getStatus() {
        return status;
    }

    public void setStatus(int status) {
        this.status = status;
    }

    @Basic
    @Column(name = "picture_id", nullable = false)
    public int getPictureId() {
        return pictureId;
    }

    public void setPictureId(int pictureId) {
        this.pictureId = pictureId;
    }

    @Basic
    @Column(name = "time", nullable = false)
    public Timestamp getTime() {
        return time;
    }

    public void setTime(Timestamp time) {
        this.time = time;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Product product = (Product) o;
        return productId == product.productId &&
                number == product.number &&
                status == product.status &&
                Objects.equals(productName, product.productName) &&
                Objects.equals(productModel, product.productModel) &&
                Objects.equals(price, product.price) &&
                Objects.equals(time, product.time);
    }

    @Override
    public int hashCode() {
        return Objects.hash(productId, productName, productModel, price, number, status, time);
    }

    @ManyToOne
    @JoinColumn(name = "picture_id1", referencedColumnName = "product_id", nullable = false)
    public Order getHtdd() {
        return htdd;
    }

    public void setHtdd(Order htdd) {
        this.htdd = htdd;
    }

    @OneToOne
    @JoinColumn(name = "pddetails_id", referencedColumnName = "pddetails_id", nullable = false)
    public Pddetails getCpxq() {
        return cpxq;
    }

    public void setCpxq(Pddetails cpxq) {
        this.cpxq = cpxq;
    }

    @ManyToOne
    @JoinColumn(name = "type_id", referencedColumnName = "type_id", nullable = false)
    public Pdtype getCpfl() {
        return cpfl;
    }

    public void setCpfl(Pdtype cpfl) {
        this.cpfl = cpfl;
    }

    @OneToMany(mappedBy = "cp")
    public List<Picture> getTp() {
        return tp;
    }

    public void setTp(List<Picture> tp) {
        this.tp = tp;
    }
}
